package com.lvyq.myplayer.ui.activity.setting

import android.content.Context
import android.widget.TextView
import com.google.android.material.button.MaterialButton
import com.lvyq.myplayer.R
import com.lvyq.myplayer.base.BaseActivity
import com.lvyq.myplayer.common.util.ManifestUtils
import com.lvyq.myplayer.common.util.UpVersion

/**
 * 文件描述：AboutActivity
 * 作者：lvyq
 * 创建时间：2025-05-19
 * 修改时间：2025-05-19
 */
class AboutActivity : BaseActivity(), UpVersion  {


    override fun getLayoutId(): Int = R.layout.activity_about

    override fun initData() {
        initAboutToolBar()
        initVersionInfo()
        initLegalLinks()

        //图标旋转
       /* val rotateAnim = ObjectAnimator.ofFloat(findViewById(R.id.iv_app_icon), "rotation", 0f, 360f)
        rotateAnim.duration = 2000
        rotateAnim.repeatCount = ValueAnimator.INFINITE
        rotateAnim.start()*/
    }

    private fun initAboutToolBar() {
       // toolbar.setTitle("关于我们")
    }

    private fun initVersionInfo() {
        // 动态获取版本信息
        val packageManager = packageManager
        val packageInfo = packageManager.getPackageInfo(packageName, 0)

        findViewById<TextView>(R.id.tv_app_name).text = getString(R.string.app_name)
        findViewById<TextView>(R.id.tv_version).text = "Version ${packageInfo.versionName}"
    }

    private fun initLegalLinks() {
        // 更新日志
        findViewById<MaterialButton>(R.id.btn_changelog).setOnClickListener {
            WebViewActivity.start(this,"version_log")
        }

        findViewById<MaterialButton>(R.id.checkVersion).setOnClickListener{
            //检测版本
            checkVersion(getAppVersionCode(this),this,true)
        }
    }

    override fun apkDownAndInstall(patchUrl: String, context: Context) {
        //读写权限
        if (!ManifestUtils.checkStoragePermission(this))  return
        //应用内安装程序权限
        if (!ManifestUtils.checkInstallAPPPermission(this))  return
        super.apkDownAndInstall(patchUrl, context)
    }

}


